//
//  TSDetailRecordTableViewCell.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/19.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import HandyJSON

struct TSDetailRecordModel : HandyJSON {
    
    var title : String!
    var addtime : Int64 = 0
    var id : Int = -1
    var qihao : Int = -1
    var ten : String!
    var nine : String!
    var egiht : String!
    var seven : String!
    var six : String!
    var five : String!
    var four : String!
    var three : String!
    var two : String!
    var one : String!
}

class TSDetailRecordTableViewCell: UITableViewCell {
    
    var titleLabel : UILabel!
    var resultLabel : UILabel!
    var dateLabel : UILabel!
    var periodLabel : UILabel!
    var line : UIView!
    var model : TSDetailRecordModel!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        configViews()
    }
    
    func setupCell(model:TSDetailRecordModel, last:Bool) {
        
        self.model = model;
        titleLabel.text = model.title
        let result = [model.one!, model.two!, model.three!, model.four!, model.five!, model.six!, model.seven!, model.egiht!, model.nine!, model.ten!] as NSArray
        resultLabel.text = result.componentsJoined(by: " ")
        dateLabel.text = Date.timeStampToString(timeStamp: model.addtime)
        periodLabel.text = "第\(model.qihao)期"
        
        line.isHidden = last
     }

    func configViews() {
        
        titleLabel = UILabel.init()
        titleLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#323232")
        titleLabel.font = UIFont.systemFont(ofSize: 15, weight: .medium)
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(15)
            make.top.equalTo(10)
        }
        
        resultLabel = UILabel.init()
        resultLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#323232")
        resultLabel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
        contentView.addSubview(resultLabel)
        resultLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(7)
        }
        
        dateLabel = UILabel.init()
        dateLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#969696")
        dateLabel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
        contentView.addSubview(dateLabel)
        dateLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.top.equalTo(resultLabel.snp.bottom).offset(7)
        }
        
        periodLabel = UILabel.init()
        periodLabel.textColor = UIColor.hexadecimalColor(hexadecimal: "#969696")
        periodLabel.font = UIFont.systemFont(ofSize: 12, weight: .medium)
        contentView.addSubview(periodLabel)
        periodLabel.snp.makeConstraints { (make) in
            make.left.equalTo(dateLabel.snp.right).offset(5)
            make.centerY.equalTo(dateLabel)
        }
        
        line = UIView.init()
        line.backgroundColor = UIColor.hexadecimalColor(hexadecimal: "#E6E6E6")
        contentView.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
            make.top.equalTo(dateLabel.snp.bottom).offset(7)
            
            make.bottom.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
